package com.xiaotao.http.controllers;

import com.xiaotao.http.core.response.MimeTypeMap;
import com.xiaotao.http.core.interfaces.Controller;
import com.xiaotao.http.core.request.HttpRequest;
import com.xiaotao.http.core.response.HttpResponse;

import java.io.File;
import java.io.IOException;

/**
 * 文件访问
 */
public class FileAccess implements Controller {
    @Override
    public void service(HttpRequest request, HttpResponse response) throws IOException {
        File file = new File("static/" + request.getURI());
        String suffix = "";
        // 若访问文件夹，使用默认首页index.html
        if (file.isDirectory()) {
            file = new File(file.getPath() + "/index.html");
        }
        response.sendFile(file);
    }
}
